*******************************************************
* Lyle 05 Jan 11: 						              *
*	-this program serves as a base shell for all	  *
*	 stata do files					                  *
*******************************************************

********************************
* Standard Stata Configuration *
********************************
clear all
set mem 999m
capture log close
set logtype text
cap cd "C:\Users\ejm5\Google Drive\2017_Research\Unemployment_MILEX"
cap cd "C:\Users\Jordan.Becker\Desktop\GD\2017_Research\Unemployment_MILEX"
cap cd "\\usnatonetapp01.eur.state.sbu\profiles\beckerjm\Desktop\2017_Research\Unemployment_MILEX"
log using "log\fiscalrules_educ_education.log", replace



*********************
* Prepare Variables *
*********************
use "dta\2017_uem", clear
sort ccode year
xtset ccode year
set more off

*Cointegration Test*
#delimit;
preserve;
tsset ccode year;

xtwest milburden fri_new, lags(1);


*Stationarity Test*
#delimit;
xtunitroot fisher milburden, dfuller lags(1) demean;

*Serial Dependency Test*
#delimit;
actest personnel, lags(1);
actest milburden, lags(1);
actest equipment, lags(1);
actest fri_new, lags(1);
restore;


#delimit;
quiet xi:xtivreg2 milburden_publiccon (fri_new=l.education), first fe robust cluster(ccode);
xi:xtpcse milburden_publiccon l.fri_new l.ln_spillins l.ln_wdi_gdp l.ln_pop l.sandler_strategic l.threat l.right l.newatlanticism years_nato i.ccode if e(sample)==1;
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse) replace;
xi:xtpcse milburden l.fri_new l.ln_spillins l.ln_wdi_gdp l.ln_pop l.sandler_strategic l.threat l.right l.newatlanticism years_nato i.ccode if e(sample)==1;
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse);


***EDUCATION INSTRUMENT***
#delimit;
xi:xtreg fri_new l.education  l.ln_wdi_gdp l.right i.ccode if e(sample)==1, robust cluster(ccode);
outreg2 using output\Table3_XTIVREG_2SLS_educ if e(sample)==1, bdec(3) tdec(3) e(rmse);

xi:xtivreg2 milburden_publiccon (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse);

xi:xtivreg2 milburden (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse);

xi:xtivreg2 equipment (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse);

xi:xtivreg2 personnel (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse);

xi:xtivreg2 operating (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse);

xi:xtivreg2 infrastructure (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
outreg2 using output\Table3_XTIVREG_2SLS_educ, bdec(3) tdec(3) e(rmse) excel;



*Calculate AIC*
#delimit;
*Baselines*
quiet xi:xtivreg2 milburden_publiccon (l.fri_new=l2.education), first fe robust cluster(ccode);
reg milburden_publiccon l.fri_new if e(sample)==1;
estimates store milburden_public_baseline;

reg milburden l.fri_new if e(sample)==1;
estimates store milburden_baseline;

reg equipment l.fri_new if e(sample)==1;
estimates store equipment_baseline;

reg personnel l.fri_new  if e(sample)==1;
estimates store personnel_baseline;

reg operating l.fri_new if e(sample)==1;
estimates store operating_baseline;

reg infrastructure l.fri_new if e(sample)==1;
estimates store infrastructure_baseline;

xi:xtivreg2 milburden_publiccon (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
estimates store milburden_publiccon;

xi:xtivreg2 milburden (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
estimates store milburden;

xi:xtivreg2 equipment (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
estimates store equipment;

xi:xtivreg2 personnel (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
estimates store personnel;

xi:xtivreg2 operating (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
estimates store operating;

xi:xtivreg2 infrastructure (l.fri_new=l2.education) l.ln_wdi_gdp l.right if e(sample)==1, first fe robust cluster(ccode);
estimates store infrastructure;

lrtest milburden_public_baseline milburden_publiccon, stats force;
lrtest milburden_baseline milburden, stats force;
lrtest equipment_baseline equipment, stats force;
lrtest personnel_baseline personnel, stats force;
lrtest operating_baseline operating, stats force;
lrtest infrastructure_baseline infrastructure, stats force;

